package com.estate.controller;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.estate.pojo.City;
import com.estate.pojo.Detail;
import com.estate.pojo.Project;
import com.estate.pojo.State;
import com.estate.service.city.CityService;
import com.estate.service.detail.DetailService;
import com.estate.service.project.ProjectService;
import com.estate.service.state.StateService;

@Controller
public class DetailController {
	
	private Logger logger = Logger.getLogger(DetailController.class);
	
	@Autowired
	private DetailService detailService;
	
	@Autowired
	private StateService stateService;
	
	@Autowired
	private CityService cityService;
	
	@Autowired
	private ProjectService projectService;
	
	@RequestMapping(value="/projectDisplay")
	public ModelAndView seeInformation(ModelAndView model){
		try {
			List<String> cityNames=cityService.selectCityNameByDetail();//查询有项目的城市
			model.addObject("cityNames",cityNames);
			List<Project> projects=projectService.allProNameAndCityName();//查询项目名称和城市名称
			model.addObject("projects", projects);
			List<Detail> details=detailService.selDetail();//查询所有项目详细信息
			model.addObject("details",details);
			model.setViewName("thymeleaf/ProjectDisplay");
		} catch (Exception e) {
			e.printStackTrace();
			model.setViewName("thymeleaf/500");
		}
		logger.info("进入项目准备页面");
		return model;
	}
	

	@RequestMapping(value="/basicdocument")
	public ModelAndView basicDocument(@RequestParam("project_id") Integer project_id,
									  @RequestParam("det_id")Integer det_id,
									  ModelAndView model) {
		try{
			Detail detail=detailService.selectDetail(project_id, det_id);
			model.addObject("detail",detail);
			List<State> states=new ArrayList<>();
			states=stateService.allState();//查询全部状态
			model.addObject("states",states);
			List<City> citys=cityService.allCity();//查询全部城市
			model.addObject("citys",citys);
			model.setViewName("thymeleaf/BasicDocument");
		}catch (Exception e) {
			e.printStackTrace();
			model.setViewName("thymeleaf/500");
		}
		logger.info("进入项目基本信息页面");
		return model;
	}
}
